package com.boottest.better.test.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boottest.better.test.configurationproperties.ConnectionServerBean;
import com.boottest.better.test.createbean.CreateBeanServerOne;
import com.boottest.better.test.server.TestServer;
import com.boottest.importsource.better.server.ImportTestServer;

@RestController
public class IndexController {

    @Value(value = "${spring.name}")
    private String value;

    @Value(value = "${age}")
    private String age;

    @Autowired
    private TestServer server;

    @Autowired
    private ImportTestServer importTestServer;

    /**
     * 通过Configuration +bean注解创建bean对象
     */
    @Autowired
    private CreateBeanServerOne serverOne;

    // 测试ConfigurationProperties Annocation
    @Autowired
    private ConnectionServerBean serverBean;

    @RequestMapping("/")
    public String getHome() {
        return "Hello World " + new Date(System.currentTimeMillis());
    }

    @RequestMapping("/testInterface")
    public String testServer() {

        server.say("laowang");
        return "success";
    }

    @RequestMapping("/importTestServer")
    public String importTestServer() throws Exception {

        importTestServer.testEat("sb..");

        System.out.println(".....get value......" + value);
        System.out.println(".....get age......" + age);

        System.out.println(serverBean);
        // if (true) throw new Exception("123456");

        return "ok";
    }

    @RequestMapping(value = "/{user}")
    public String getParam(@PathVariable String user) {

        serverOne.gangsheng();

        return user + " hello world";

    }

}
